<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-31 17:46:49
 * @LastEditTime: 2020-03-12 09:45:49
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .van-search {
            /* background: transparent !important; */
            padding: 6px 0;
            border-bottom: 1px solid #ebedf0;
        }

        /* .van-search__content {
             background: transparent
         } */

        .van-search__action {
            color: #cd1b21;
            font-size: 13px;
            font-weight: 700;
        }

        .result {
            position: absolute;
            left: 0;
            top: 47px;
            bottom: 0;
            right: 0;
            overflow-x: hidden;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        .mt {
            margin-top: 10px;
        }

        .border {
			border-right: 1px solid #ebedf0;
		}

        .label {
			line-height: 22px;
			text-align: center;
			font-weight: 500;
            font-size: 13px;
            color: #969799;
            padding: 8px 0;
		}

		.label .label-value {
			color: #3a3a3a;
			font-size: 14px;
		}

        .van-panel__header-value {
            color: #969799;
        }

        .oun{
            color: #969799;
        }

        .un {
            color: #cd1b21;
        }

        .van-cell__title {
            max-width: 90%;
        }

        .van-cell__value {
            text-align: right;
        }

        .tab {
            overflow: hidden;
            position: absolute;
            left: 0;
            top: 0;
            width: 130px;
            padding-left: 10px;
            height: 47px;
            line-height: 55px;
            background: rgb(255, 255, 255);
            border-bottom: 1px solid #ebedf0;
        }

        .tab .t-d {
            font-size: 0;
            border-radius: 6px;
        }

        .tab .t-d>div {
            display: inline-block;
            width: 55px;
            text-align: center;
            height: 24px;
            font-size: 13px;
            border: 1px solid #cd1b21;
            line-height: 22px;
        }

        .tab .t-d>div.on {
            background: #cd1b21;
            color: #fff;
            line-height: 22px;
        }

        .total {
            position: absolute;
            left: 0;
            bottom: 0;
            height: 50px;
            width: 100%;
            padding: 0 15px;
            line-height: 50px;
            font-size: 14px;
            background: #fff;
            box-shadow: 0 0 5px rgb(200, 198, 198);
        }

        .money {
            font-size: 16px;
            font-weight: 700;
            color: #cd1b21;
            margin-left: 15px;
        }
        .elp{
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
            max-width: 200px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" :title="'客户列表(' + filterResult.length + ')'" left-arrow @click-left="onClickLeft">
            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <div style="position: relative;background: #fff;">
                        <div class="tab">
                            <div class="t-d">
                                <div :class="filterData.S_Type == 10?'on':''" @click="toggleActive(10)">开通</div>
                                <div :class="filterData.S_Type == 15?'on':''" @click="toggleActive(15)">应收</div>
                            </div>
                        </div>
                        <div style="padding-left: 130px;">
                            <form action="">
                                <van-search v-model="filterData.S_Cont" placeholder="请输入搜索关键词" show-action
                                    @search="getSearchList">
                                    <div slot="action" @click="getSearchList">查询</div>
                                </van-search>
                            </form>
                        </div>

                    </div>
                    <div class="result">
                        <div v-if="filterData.S_Type == 10">
                            <van-panel class="mt" v-for="(row,index) in filterResult"
                                 @click="intoDetail(row,index)">
                                <div slot="header">
                                    <van-cell :title="row.name" is-link>
                                        <div :class="row.IsOPAP==0?'un':'oun'">{{row.IsOPAP==0?'未开通':'已开通'}}</div>
                                    </van-cell>
                                </div>
                                <div class="label">
                                    <van-row gutter="8">
                                            <van-col span="8">
                                                    <div>客户类别</div>
                                                    <div class="label-value">{{row.TrName || '--'}}</div>
                                                </van-col>
                                        <van-col span="8">
                                            <div>联系人</div>
                                            <div class="label-value">{{row.LinkMan || '--'}}</div>
                                        </van-col>
                                        
                                        <van-col span="8">
                                            <div>应收</div>
                                            <div class="label-value">{{row.AXMoney}}</div>
                                        </van-col>

                                    </van-row>
                                </div>
                                <div slot="footer" style="text-align: right">
                                        <van-button size="small" :type="row.IsMdf === 1?'warning':'default'" @click.stop="openGoodsShelves(row)">货架查询
                                            </van-button>
                                    <van-button size="small" type="info" @click.stop="openConsignmentInventory(row)">代销库存
                                    </van-button>
                                    <van-button v-if="row.IsOPAP==0" :disabled="ifConfirm" :loading="ifConfirm"
                                        size="small" type="primary" @click.stop="openCustomer(row)">开通账户</van-button>
                                </div>
                            </van-panel>

                        </div>
                        <div v-if="filterData.S_Type == 15">
                            <div class="report" style="padding-bottom: 50px;">
                                <div class="table-full">
                                    <table>
                                        <tr>
                                            <th>序号</th>
                                            <th>客户</th>
                                            <th>应收</th>
                                        </tr>
                                        <tr v-for="(row,index) in filterResult">
                                            <td class="td_center">{{index+1}}</td>
                                            <td><div class="elp">{{row.name}}</div></td>
                                            <td class="td_right">{{row.AXMoney}}</td>
                                        </tr>
                                    </table>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="total" v-if="filterData.S_Type == 15">合计应收<span class="money">￥{{getToalAX()}}</span>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();

        api.addEventListener({
            name: 'setCustomerListData'
        }, function (ret, err) {
            vm.$set(vm.filterResult,vm.index, ret.value.customerData)

        })

        var userInfo = FLD.getUserInfo();
        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                ifConfirm: false,
                index:-1,
                filterData: {
                    S_Type: 10,
                    S_Cont: '',
                    S_BranchID: userInfo.S_BranchID,
                    S_SXZ: '',
                    S_StockID: userInfo.S_StockID,
                    S_CargoID: userInfo.S_CargoID,
                    S_BarCode: '',
                    S_PriceN: userInfo.S_PriceN,
                    S_ProductID: 0
                },
                filterResult: []
            },
            created: function () {
                this.getSearchList();
            },
            methods: {
                getSearchList() {
                    var that = this;
                    that.showLoading = true;
                    FLD.ajax('AP_BasList', that.filterData, function (res) {
                        that.showLoading = false;
                        that.filterResult = res.ds;
                    })
                },
                toggleActive(index) {
                    var that = this;
                    that.filterData.S_Type = index
                    that.getSearchList();
                },
                getToalAX() {
                    var that = this;
                    var money = 0;
                    for (var i in that.filterResult) {
                        money += that.filterResult[i].AXMoney;
                    }
                    return money.toFixed(2)
                },
                openGoodsShelves(row){
                    api.openWin({
                        name: 'goodsShelves',
                        url: 'goodsShelves.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            clientInfo: row
                        }
                    })
                },
                openConsignmentInventory(row) {
                    api.openWin({
                        name: 'consignmentInventory',
                        url: 'consignmentInventory.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            clientInfo: row
                        }
                    })
                },
                openCustomer(row) {
                    var that = this;

                    this.$dialog.confirm({
                        title: '提示',
                        message: '是否开通此客户?'
                    }).then(() => {
                        that.ifConfirm = true;
                        var obj = {
                            S_ClientID: row.id,
                            S_BranchID: userInfo.S_BranchID
                        }
                        FLD.ajax('AP_ADClientNI', obj, function (res) {
                            that.ifConfirm = false;
                            if (res.ds[0].status == 500) {
                                layer.open({
                                    content: res.ds[0].msg,
                                    skin: 'msg',
                                    time: 2
                                });
                            } else {
                                row.IsOPAP = 1;
                                layer.open({
                                    content: '客户启用成功!',
                                    skin: 'msg',
                                    time: 2
                                });
                            }
                        })

                    }).catch(() => {

                    });

                },
                intoDetail(row,index){
                    var that = this;
                    that.index = index;
                    api.openWin({
                        name: 'customersDetail',
                        url: 'customersDetail.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            customerData: row
                        }
                    })
                },
                onClickLeft() {
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>